\section{Code for problem 1}
\label{code1}
\small
\begin{verbatim}
# The g function: g(alpha)=alpha-log(kappa(alpha))
gFunc <- function(alpha)
{
  return(alpha-2*log(3/(3-alpha)))
}

# Plots the g function in order to establish that we have found the correct optimal alpha
t<-(10:290)/100
plot(t,gFunc(t), type='l', xlab="alpha", ylab="g(alpha)")
abline(v=1)
abline(h=gFunc(1))

# The number of repetitions of z that we are interested in
N<-100000
# Draws a vector of s_{100}'s
sample <- rgamma(N, shape = 200, rate = 2)
# Calculates the vector of z's from the vector of s_{100}'s
z <- (sample>100) * exp(-(sample-200*log(3/2)))

# Estimates the probability, and the variance and skewness of the estimate
mean(z)
var(z)
mean(((z-mean(z))/sqrt(var(z)))^3)

# Calculates error bounds for the estimate
mean(z)-1.96*sqrt(var(z))/sqrt(N)
mean(z)+1.96*sqrt(var(z))/sqrt(N)

# Plots a histogram of the simulated probabilities
hist(z,50)

# In the following code we do the same thing as above
# except we doesn't simulate s_{100} directly, but as
# a sum og 100 X_i's with Gamma(2,2) distribution.
N<-10000
z <- c()
for(i in 1:N)
{
  sample <- rgamma(100, shape = 2, rate = 2)
  temp <- (sum(sample)>100) * exp(-(sum(sample)-200*log(3/2)))
  z <- c(z,temp)
}

mean(z)
var(z)
mean(((z-mean(z))/sqrt(var(z)))^3)
\end{verbatim}

% True value can be found like this in R:
% 1 - pgamma(1, shape = 200, rate = 300)

\newpage